package com.matt.repository.estimate;

import com.matt.domain.estimate.TeacherExtendEstimate;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TeacherExtendEstimateRepository extends JpaRepository<TeacherExtendEstimate, String> {
    /**
     * 分页 时间逆序
     * @param areaId
     * @return
     */
    @Query(value = "SELECT * FROM teacher_extend_estimate WHERE areaId = ? ORDER BY createDate DESC", nativeQuery = true)
    List<TeacherExtendEstimate> listTeacherEstimateByAreaId(@Param("areaId") String areaId);

    @Query(value = "SELECT * FROM teacher_extend_estimate WHERE areaId = ? and childrenId=?  ORDER BY createDate DESC", nativeQuery = true)
    List<TeacherExtendEstimate> listTeacherEstimateByAreaIdAndStaffId(@Param("areaId") String areaId,@Param("childrenId") String childrenId);

    @Query(value = "SELECT * FROM teacher_extend_estimate WHERE id = ?", nativeQuery = true)
    TeacherExtendEstimate findByTeacherEstimateId(String estimateId);

    // 新增
//    @Query(value = "INSERT INTO teacher_extend_estimate() VALUES()", nativeQuery = true)
//    String addTeacherEstimate(String );

    // 修改
    @Modifying
    @Query(value = "UPDATE teacher_extend_estimate SET(parentId = ?, staffId = ?, rating = ?, teacherContent = ? , evaluatorId = ?) WHERE id = ?  ", nativeQuery = true)
    String updateTeacherEstimate(String parentId, String staffId, String rating, String teacherContent, String evaluatorId, String id);

    // 删除
//    @Modifying
//    @Transactional
//    @Query(value = "DELETE FROM teacher_extend_estimate WHERE id = ?1", nativeQuery = true)
//    String deleteByTeacherEstimateId(String estimateId);

    // 详情
    @Query(value = "SELECT * FROM teacher_extend_estimate WHERE WHERE id = ?1", nativeQuery = true)
    TeacherExtendEstimate getByTeacherEstimateId(String estimateId);

}
